#include<iostream>
using namespace std;
int main()
{
    int n = 0;
    cin >> n;

    int a = 0, b = 1;
    int c = a + b;
    while (n > c)
    {
        a = b;
        b = c;
        c = a + b;
    }



    cout << min(c - n, n - b);
    return 0;
}